package com.liuyi.producer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class PorductProducer {
	
	private Store<Porduct> mStore;
    private static ExecutorService mWorkThread = Executors.newFixedThreadPool(1);
    private String name;

    public PorductProducer setName(String name) {
        this.name = name;
        return this;
    }

    public PorductProducer bindStore(Store<Porduct> store) {
        this.mStore = store;
        return this;
    }

    public void production() {
        mWorkThread.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
                Porduct apple = new Porduct("第" + name + "个产品");
                mStore.push(apple);
            }
        });
    }
}
